package com.resurvolution.kingcloudmusicspringboot.product.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.resurvolution.kingcloudmusicspringboot.product.entity.GenreEntity;
import com.resurvolution.kingcloudmusicspringboot.product.mapper.GenreMapper;
import com.resurvolution.kingcloudmusicspringboot.product.service.GenreService;
import com.resurvolution.kingcloudmusicspringboot.product.vo.GenreVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class GenreServiceImpl extends ServiceImpl<GenreMapper, GenreEntity> implements GenreService {

    @Resource
    private GenreMapper genreMapper;

    @Override
    public List<GenreVO> getGenres() {
        QueryWrapper<GenreEntity> queryWrapper = new QueryWrapper<>();
        return genreMapper.selectList(queryWrapper)
                .stream()
                .map((entity) -> {
                    GenreVO vo = new GenreVO();
                    vo.setId(entity.getId());
                    vo.setName(entity.getName());
                    return vo;
                })
                .collect(Collectors.toList());
    }

    @Override
    public String getGenreById(Integer id) {
        QueryWrapper<GenreEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("genre_id", id);
        GenreEntity genreEntity = genreMapper.selectOne(queryWrapper);
        return genreEntity.getName();
    }
}
